/**
* @file test.c
* @brief this is a brief description
* @details this is the detail description.
* @author fulong 
* @data 2014/12/20
* @version 1.0
* @par Copyright (c):
* @par First build
*     version: fulong 
*     data: 2014/12/20
*/
#include "board_test.h"
#include "../hal/action/action.h"
#include "../dev/input.h"
#include "../dev/uart.h"
#include "../dev/io_configure.h"
#include "../lib/delay.h"
#include "../hal/e2prom.h"
#include "../hal/stepper_motor.h"
#include "../app/menu/menu_common.h"
#include "../app/menu/menu_process.h"
#include "../hal/hal_key.h"
extern input_status_process status_process;
extern hal_key_struct hal_key_proc;
#ifdef __BOARD_TEST__
    #ifdef __XT14012__
uint8 test_num = 0;
uint32 old_test_led = 0;
static void XT14012_test(void)
{
    uint16 i = 0;
    if (!IN0 || !IN1 || !IN2 || !IN3 || !IN4 || !IN5 || !IN6 || !IN7 || !IN10 || !IN11 || !IN12 || !IN13)
    {
        action_output_ctrl.action_output_byte = 0;
        if (!IN0)
        {
            Y00 = 1;
            stepper_motor_speed_up();
        }
        if (!IN1)
        {
            Y01 = 1;
        }
        if (!IN2)
        {
            Y02 = 1;
        }
        if (!IN3)
        {
            Y03 = 1;
        }
        if (!IN4)
        {
            Y04 = 1;
        }
        if (!IN5)
        {
            Y05 = 1;
        }
        if (!IN6)
        {
            Y06 = 1;
        }
        if (!IN7)
        {
            Y07 = 1;
        }
        if (!IN10)
        {
            Y10 = 1;
        }
        if (!IN11)
        {
            Y11 = 1;
        }
        if (!IN12)
        {
            Y12 = 1;
        }
        if (!IN13)
        {
            Y13 = 1;
        }
    } else
    {
        action_output_ctrl.action_output_byte = old_test_led;
        apply4delay(ACTION_DELAY_FLAG, 500);
        if (get_delay_flag(ACTION_DELAY_FLAG))
        {
            switch (test_num)
            {
                case 0 :
                    Y00 = 1;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 1 :
                    Y00 = 0;
                    Y01 = 1;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 2 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 1;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 3 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 1;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    set_output_value(3, 0);
                    break;
                case 4 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 1;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 5 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 1;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 6 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 1;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 7 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 1;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 8 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 1;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 9 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 1;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 10 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 1;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 11 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 1;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 12 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 1;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 1;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 13 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 1;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 0;
                    break;
                case 14 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 1;
                    Y17 = 0;
                    Y20 = 0;
                    if (Y16)
                    {
                        change_dr1(1);
                    } else
                    {
                        change_dr1(0);
                    }
                    break;
                case 15 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 1;
                    Y20 = 0;
                    if (Y17)
                    {
                        change_dr3(1);
                    } else
                    {
                        change_dr3(0);
                    }
                    break;
                case 16 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    Y06 = 0;
                    Y07 = 0;
                    Y10 = 0;
                    Y11 = 0;
                    Y12 = 0;
                    Y13 = 0;
                    Y14 = 0;
                    Y15 = 0;
                    Y16 = 0;
                    Y17 = 0;
                    Y20 = 1;
                    if (Y20)
                    {
                        change_dr2(1);
                    } else
                    {
                        change_dr2(0);
                    }
                    break;
                case 17 :
//                    Y21 = !Y21;
                    break;
                default:
                    break;
            }
            test_num++;
            test_num %= OUTPUT_MAX_NUM;
            clr_delay_flag(ACTION_DELAY_FLAG);
            old_test_led = action_output_ctrl.action_output_byte;
        }
    }
    if (hal_key_proc.hal_key_len > 0)
    {
        while (hal_key_proc.hal_key_saved[hal_key_proc.hal_key_len - 1] >> i)
        {
            i++;
        }
    }
}
    #endif
    #ifdef __XT14042__
extern display_text_widget_struct watch_dis_text0;
extern display_text_widget_struct watch_dis_text1;
extern display_text_widget_struct watch_dis_text2;
uint8 test_num = 0;
uint32 old_test_led = 0;
static void XT14042_test(void)
{
    uint16 i = 0;
    if (!IN0 || !IN1 || !IN2 || !IN3 || !IN4 || !IN5 || !IN6 || !IN7)
    {
        action_output_ctrl.action_output_byte = 0;
        if (!IN0)
        {
            Y00 = 1;
        }
        if (!IN1)
        {
            Y01 = 1;
        }
        if (!IN2)
        {
            Y02 = 1;
        }
        if (!IN3)
        {
            Y03 = 1;
        }
        if (!IN4)
        {
            Y04 = 1;
        }
        if (!IN5)
        {
            Y05 = 1;
        }
        if (!IN6)
        {
            watch_dis_text0.dis_var = 6;
        }
        if (!IN7)
        {
            watch_dis_text0.dis_var = 7;
        }
    } else
    {
        action_output_ctrl.action_output_byte = old_test_led;
        apply4delay(ACTION_DELAY_FLAG, 500);
        if (get_delay_flag(ACTION_DELAY_FLAG))
        {
            switch (test_num)
            {
                case 0 :
                    Y00 = 1;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    break;
                case 1 :
                    Y00 = 0;
                    Y01 = 1;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    break;
                case 2 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 1;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 0;
                    break;
                case 3 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 1;
                    Y04 = 0;
                    Y05 = 0;
                    break;
                case 4 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 1;
                    Y05 = 0;
                    break;
                case 5 :
                    Y00 = 0;
                    Y01 = 0;
                    Y02 = 0;
                    Y03 = 0;
                    Y04 = 0;
                    Y05 = 1;
                    break;
                default:
                    break;
            }
            watch_dis_text0.dis_var = 0;
            test_num++;
            test_num %= OUTPUT_MAX_NUM;
            clr_delay_flag(ACTION_DELAY_FLAG);
            old_test_led = action_output_ctrl.action_output_byte;
        }
    }
}
    #endif
    #ifdef __XT11033__
extern display_text_widget_struct watch_dis_text0;
extern display_text_widget_struct watch_dis_text1;
extern display_text_widget_struct watch_dis_text2;
uint8 test_num = 0;
uint32 old_test_led = 0;
static void XT11033_test(void)
{
    if (test_num != 0)
    {
        watch_dis_text0.dis_var = old_test_led % 10;
        watch_dis_text1.dis_var = (old_test_led / 10) % 10;
        watch_dis_text2.dis_var = (old_test_led / 100) % 10;
        apply4delay(ACTION_DELAY_FLAG, 2000);
        if (get_delay_flag(ACTION_DELAY_FLAG))
        {
            test_num = 0;
            clr_delay_flag(ACTION_DELAY_FLAG);
        }
    } else
    {
        apply4delay(ACTION_DELAY_FLAG, 10000);
        Y11 = 0;
        if (get_delay_flag(ACTION_DELAY_FLAG))
        {
            Y11 = 1;
            old_test_led++;
            test_num = 1;
            clr_delay_flag(ACTION_DELAY_FLAG);
        }
    }
}
    #endif
    #ifdef __XT14032__
        #include "../dev/LM35DZ.h"
extern display_text_widget_struct watch_dis_text0;
extern display_text_widget_struct watch_dis_text1;
extern display_text_widget_struct watch_dis_text2;
uint8 test_num = 0;
uint32 old_test_led = 0;
static void XT14032_test(void)
{
}
    #endif
void board_test(void)
{
#ifdef __XT14042__
    XT14042_test();
#endif
#ifdef __XT11033__
    XT11033_test();
#endif
#ifdef __XT14012__
    XT14012_test();
#endif
#ifdef __XT14032__
    XT14032_test();
#endif
}
#endif

